import { track } from '@vercel/analytics'

export const trackPromotionEvent = (event: string, properties: Record<string, string>) => {
  // 记录推广事件
  track(event, properties) // 记录事件

  // @ts-expect-error gtag is not defined in the window object
  if (typeof window !== 'undefined' && window?.gtag) {
    // 如果在浏览器环境且 gtag 已定义
    try {
      window.gtag('event', event, { ...properties }) // 记录事件
      if (properties.action_detail) {
        window.gtag('event', properties.action_detail) // 记录详细动作
      }
    } catch (error) {
      console.error(error)
    }
  }
}
